package cn.sh.yhk.configure.filter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

//@Configuration
public class FilterConfig {
    @Value("${server.excludeurl}")
    private String url;


    @Bean
    public FilterRegistrationBean SessionFilter() {
        FilterRegistrationBean SessionFilter = new FilterRegistrationBean();
        SessionFilter.setName("SessionFilter");
        SessionFilter.setFilter(new SessionFilter());
        SessionFilter.addUrlPatterns("/*");
        SessionFilter.setOrder(10);//order的数值越小 则优先级越高
        SessionFilter.addInitParameter("excludeUrl", url);
        return SessionFilter;
    }

    //@Bean
    public FilterRegistrationBean PrintParamterFilter() {
        FilterRegistrationBean PrintParamterFilter = new FilterRegistrationBean();
        PrintParamterFilter.setName("PrintParamterFilter");
        PrintParamterFilter.setFilter(new PrintParamterFilter());
        PrintParamterFilter.addUrlPatterns("/*");
        PrintParamterFilter.setOrder(999);//order的数值越小 则优先级越高
        return PrintParamterFilter;
    }

    /**
     * 配置javamelody监控
     * spring boot 会按照order值的大小，从小到大的顺序来依次过滤
     */
//    @Bean
//    public FilterRegistrationBean<MonitoringFilter> monitoringFilter() {
//        FilterRegistrationBean<MonitoringFilter> registration = new FilterRegistrationBean<MonitoringFilter>();
//        registration.setFilter(new MonitoringFilter());
//        registration.addUrlPatterns("/*");
//        registration.setOrder(Integer.MAX_VALUE);
//        registration.setName("monitoring");
//        return registration;
//    }

    /**
     * 配置javamelody监听器sessionListener
     */
//    @Bean
//    public ServletListenerRegistrationBean<SessionListener> servletListenerRegistrationBean() {
//        ServletListenerRegistrationBean<SessionListener> slrBean = new ServletListenerRegistrationBean<SessionListener>();
//        slrBean.setListener(new SessionListener());
//        return slrBean;
//    }
//

//
//    @Bean
//    public FilterRegistrationBean filterRegistrationBean2() {
//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
//        filterRegistrationBean.setFilter(new AuthorFilter());
//        filterRegistrationBean.addUrlPatterns("/*");
//        filterRegistrationBean.setOrder(2);
//        return filterRegistrationBean;
//    }

}
